// run: $exec < input
#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <set>

int const maxn = 1000007;
int a[maxn], b[maxn];
int n;

int main()
{
	int T;
	std::scanf("%d", &T);
	for (int ti = 1; ti <= T; ti++) {
		std::unordered_map<int, std::set<int>> forward_trans;
		std::unordered_map<int, std::set<int>> reverse_trans;
		std::unordered_map<int, bool> not_self_trans;
		std::set<int> clusters;
		std::unordered_map<int, int> result;
		std::cin >> n;
		for (int i = 0, x, y; i < n; i++) {
			std::scanf("%d %d", &x, &y);
			a[i] = x;  b[i] = y;
			forward_trans[x].insert(y);
			reverse_trans[y].insert(x);
			if (x != y) {
				not_self_trans[x] = true;
				not_self_trans[y] = true;
			}
			clusters.insert(x);
			clusters.insert(y);
		}

		int split = 0, merge = 0, keep = 0;

		for (int i = 0; i < n; i++) {
			int x = a[i], y = b[i];
			int ta = forward_trans[x].size();
			int tb = reverse_trans[y].size();
			if (ta > 1 && (tb > 1 || result[x] == 3))
				result[x] = 4;
			else if (ta > 1) result[x] = 2;
			else if (ta == 1 & tb > 1) result[x] = 3;
		}

		for (auto i : clusters) {
			if (!result[i]) keep++;
			else if (result[i] == 2) split++;
			else if (result[i] == 3) merge++;
		}

		std::printf("Case #%d: %d %d %d\n", ti, split, merge, keep);
	}
}


